package com.example.personnel.controller;

import com.example.personnel.model.Personnel;
import com.example.personnel.service.PersonnelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/personnel")
public class PersonnelController {
    @Autowired
    private PersonnelService personnelService;
    
    @PostMapping
    public ResponseEntity<?> addPersonnel(@RequestBody Personnel personnel) {
        return ResponseEntity.ok(personnelService.addPersonnel(personnel));
    }
    
    @GetMapping("/search")
    public ResponseEntity<?> searchPersonnel(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String position,
            @RequestParam(required = false) String gender,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size) {
        Page<Personnel> result = personnelService.searchPersonnel(name, position, gender, page, size);
        return ResponseEntity.ok(result);
    }
    
    @PutMapping("/{id}")
    public ResponseEntity<?> updatePersonnel(@PathVariable Long id, @RequestBody Personnel personnel) {
        return ResponseEntity.ok(personnelService.updatePersonnel(id, personnel));
    }
   @DeleteMapping("/{id}")
    public ResponseEntity<?> deletePersonnel(@PathVariable Long id) {
        personnelService.deletePersonnel(id);
        return ResponseEntity.ok().build();
    } 
   
} 